(function () {

var $modal = $('#pop-modal');
var iShopId = parseInt(page.url.get('id'));	 
	//获取店铺首页幻灯片
	getShopwidget();
	function getShopwidget()
	{
		//导航
		getJson(Domain+'/comm/widget/doSearchShopWidgetData.do', {
			widgetName:'shop_pc_top_navigation',
			widgetDataType:2,
			shopId:iShopId
		}, function (res) {
		  
		  if(!res.success){
	
		    $('.am-modal-bd').text(res.errorMessage);
				$modal.modal();
				setTimeout(function () {
					$modal.modal('close');
				},iWiating);

		  }
		  else{

		  	console.log(res);
	  	 	renderTmp('#urllist', 'urllisttpl',res);

		  }
		});

		//幻灯
		getJson(Domain+'/comm/widget/doSearchShopWidgetData.do', {
			widgetName:'shop_pc_top_slide',
			widgetDataType:2,
			shopId:iShopId
		}, function (res) {
		  
		  if(!res.success){
	
		    $('.am-modal-bd').text(res.errorMessage);
				$modal.modal();
				setTimeout(function () {
					$modal.modal('close');
				},iWiating);

		  }
		  else{

	  	 	console.log(res);

		  }
		});
	};

	//获取优惠券
	getCouponList ();
	function getCouponList ()
	{
		getJson(Domain+'/shop/doSearchShopCashCouponList.do', {
			id:iShopId
		}, function (res) {
		  
		  if(!res.success){
	
		    $('.am-modal-bd').text(res.errorMessage);
				$modal.modal();
				setTimeout(function () {
					$modal.modal('close');
				},iWiating);

		  }
		  else{

	  	 	renderTmp('#couponlist', 'couponlisttpl',res);

		  }
		});
	}


	//商家推荐商品
	getRecomentedGoods ();
	function getRecomentedGoods ()
	{
		getJson(Domain+'/shop/doSearchShopRecGoodList.do', {
			id:iShopId,
			limit:3
		}, function (res) {
		  
		  if(!res.success){
	
		    $('.am-modal-bd').text(res.errorMessage);
				$modal.modal();
				setTimeout(function () {
					$modal.modal('close');
				},iWiating);

		  }
		  else{

	  	 	renderTmp('#recgoodslist', 'recgoodslisttpl',res);
	  	 	lazyLoad.refresh(true);

		  }
		});
	}

	//获取商铺信息
	getShopInfo ();
	function getShopInfo ()
	{
		getJson(Domain+'/shop/doLoadShopInfo.do', {
			id:iShopId
		}, function (res) {
		  
		  if(!res.success){
	
		    $('.am-modal-bd').text(res.errorMessage);
				$modal.modal();
				setTimeout(function () {
					$modal.modal('close');
				},iWiating);

		  }
		  else{

	  	 	renderTmp('#shopinfo', 'shopinfotpl',res);
	  	 	
		  }
		});
	}

	 getPageData({
	 	id:iShopId+''  //默认显示商品条数
	 });
	 function getPageData (Filter)
	 {
	 	var Filter = Filter;
	 		Filter.page = page.page;
	 		Filter.pageSize = page.pageSize;

	 	getJson(Domain+'/shop/doSearchShopGoodsList.do', Filter, function (res) {
		  if(!res.success){
	
		    $('.am-modal-bd').text(res.errorMessage);
				$modal.modal();
				setTimeout(function () {
					$modal.modal('close');
				},iWiating);

		  }
		  else{

	  		  page.nowPage = res.data.pageId;
      		  page.pageCount = res.data.pageCount;
      		  
      		  if(!res.data.rows.length){
		        $('.am-pagination').remove();
		        $('#itemlist').empty();
		        $('#itemlist').append('<li class="empty_div">'+language.noGoods+'</li>');
		        return
		      }

		     $('.list-body').empty();

			 renderTmp('#itemlist', 'itemlisttpl',res);

			 	lazyLoad.refresh(true);
			 	$('.am-pagination').createPage({
			        current: page.page,
			        type: 1,
			        pageCount: page.pageCount,
			        center: 3,
			        showLen: 11,
		        callback: function (curidx, obj) {
		          page.page = curidx;
		          $('#itemlist').empty();
		          getPageData(Filter);
		        }
		       });

			 	$('.textpage').createPage({
			        current: page.page,
			        type: 2,
			        pageCount: page.pageCount,
		        callback: function (curidx, obj) {
		          page.page = curidx;
		          $('#itemlist').empty();
		          getPageData(Filter);
		        }
		       });
		  }
		})
	 }
})();